package com.zhang.bglogin.controller;


import com.zhang.bglogin.pojo.User;
import com.zhang.bglogin.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

@RestController
@CrossOrigin
public class UserController {
  @Autowired
  UserService userService;

  @RequestMapping("/api/login")
  public String login(User user){
    boolean flag = userService.login(user);
    if(flag==true){
      return "{\n" + "  \"status\": 0,\n" + "  \"message\": \"登录成功！\",\n"
          + "  \"token\": \"Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6MSwidXNlcm5hbWUiOiJhZG1pbiIsInBhc3N3b3JkIjoiIiwibmlja25hbWUiOiLms6Xlt7Tlt7QiLCJlbWFpbCI6Im5pYmFiYUBpdGNhc3QuY24iLCJ1c2VyX3BpYyI6IiIsImlhdCI6MTU3ODAzNjY4MiwiZXhwIjoxNTc4MDcyNjgyfQ.Mwq7GqCxJPK-EA8LNrtMG04llKdZ33S9KBL3XeuBxuI\"\n"
          + "}";
    }else {
      return "{\n" + "  \"status\": 1,\n" + "  \"message\": \"登录失败！\",\n"
          + "  \"token\": \"\"\n" + "}";
    }
  }

  @RequestMapping("/api/reguser")
  public String reg(User user){

    boolean flag = userService.reg(user);
    if(flag==true){
      return "{\n" + "  \"status\": 0,\n" + "  \"message\": \"注册成功！\"\n" + "}";
    }else{
      return "{\n" + "  \"status\": 1,\n" + "  \"message\": \"注册失败！\"\n" + "}";
    }
  }
}